#! /bin/bash

registry=127.0.0.1:5000
registry_staging=registry.cn-shenzhen.aliyuncs.com/crlandpmrepo
registry_prod=registry.cn-shenzhen.aliyuncs.com/crlandpmrepo
registry_test=registry.cn-shenzhen.aliyuncs.com/crlandpmrepo
repository_dev=customer_service_front_dev
repository_test=customer_service_front_test
repository_staging=customer_service_front_staging
repository_prod=customer_service_front_prod
git_commit_id=`git rev-parse --short HEAD`
commit_time=`date +%Y%m%d%H%M%S`

export NODE_ENV=$1
#如果没输入参数，提示数据参数test,staging,prod,test代表测试环境，staging代表预生产, prod代表正式环境
if [ $# != 1 ];then
    echo “input parameter:dev, test, staging or prod”
    exit 1;
elif [ $1 != "dev" ] && [ $1 != "test" ] && [ $1 != "staging" ] && [ $1 != "prod" ];then
    echo “input one of the parameters:dev, test, staging or prod”
    exit 1;
fi
npm install
if [ $1 == "dev" ];then
    npm run build-dev
    docker build --build-arg PUBLISH_ENV=${NODE_ENV} -t ${registry}/${repository_dev}:${commit_time}_${git_commit_id} .
    echo ${registry}/${repository_dev}:${commit_time}_${git_commit_id}
fi
if [ $1 == "test" ];then
    npm run build-test
    docker build --build-arg PUBLISH_ENV=${NODE_ENV} -t ${registry_test}/${repository_test}:${commit_time}_${git_commit_id} .
    echo ${registry_test}/${repository_test}:${commit_time}_${git_commit_id}
fi
if [ $1 == "staging" ];then
    npm run build-staging
    docker build --build-arg PUBLISH_ENV=${NODE_ENV} -t ${registry_staging}/${repository_staging}:${commit_time}_${git_commit_id} .
    echo ${registry_staging}/${repository_staging}:${commit_time}_${git_commit_id}
fi
if [ $1 == "prod" ];then
    npm run build-prod
    docker build --build-arg PUBLISH_ENV=${NODE_ENV} -t ${registry_prod}/${repository_prod}:${commit_time}_${git_commit_id} .
    echo ${registry_prod}/${repository_prod}:${commit_time}_${git_commit_id}
fi
